package com.lyl.util;

import lombok.Getter;

@Getter
public class ResultJson<T> {
    private Integer code;
    //编码
    private String message;
    /*提示成功或者失败*/
    private T obj;


    private ResultJson(ResultCode resultCode, T obj) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.obj = obj;
    }
    private ResultJson(ResultCode resultCode, T obj,String message) {
        this.code = resultCode.getCode();
        this.message =message;
        this.obj = obj;
    }
    public  static <T> ResultJson<T> getInstance(ResultCode resultCode,T obj){
            return new ResultJson<>(resultCode,obj);
    }
    public  static <T> ResultJson<T> getInstance(ResultCode resultCode,T obj,String message){
        return new ResultJson<>(resultCode,obj,message);
    }
    public  static <T> ResultJson<T> success(T obj,String message){
        return getInstance(ResultCode.SUCCESS,obj,message);
    }
    public  static <T> ResultJson<T> success(T obj){
        return getInstance(ResultCode.SUCCESS,obj);
    }
    public  static <T> ResultJson<T> error(){
        return getInstance(ResultCode.ERROR,null);
    }
    public  static <T> ResultJson<T> error(String  message){
        return getInstance(ResultCode.ERROR,null,message);
    }
}
